home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / kings_audience.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  7.4 KB  |  269 lines

  1. ; AisleRiot - king's_audience.scm
  2. ; Copyright (C) 2005 Zach Keene
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define stock 11)
  20. (define waste 12)
  21. (define reserves '(0 1 2 3 4 9 10 13 14 19 20 21 22 23 24 25))
  22. (define royal-discards '(5 6 7 8))
  23. (define foundations '(15 16 17 18))
  24.  
  25. (def-save-var open-royal 5)
  26. (def-save-var open-foundation 15)
  27.  
  28. (define (new-game)
  29.   (initialize-playing-area)
  30.   (make-standard-deck)
  31.   (shuffle-deck)
  32.  
  33.   (add-blank-slot)
  34.   (add-normal-slot '())         ; slot 0
  35.   (add-normal-slot '())         ; slot 1
  36.   (add-normal-slot '())         ; slot 2
  37.   (add-normal-slot '())         ; slot 3
  38.   (add-carriage-return-slot)
  39.  
  40.   (add-raised-slot '())         ; slot 4
  41.   (add-extended-slot '() right) ; slot 5 (discard)
  42.   (add-extended-slot '() right) ; slot 6 (discard)
  43.   (add-extended-slot '() right) ; slot 7 (discard)
  44.   (add-extended-slot '() right) ; slot 8 (discard)
  45.   (add-raised-slot '())         ; slot 9
  46.   (add-carriage-return-slot)
  47.  
  48.   (add-raised-slot '())         ; slot 10
  49.   (add-blank-slot)
  50.   (add-normal-slot DECK)        ; slot 11 (stock)
  51.   (add-normal-slot '())         ; slot 12 (waste) 
  52.   (add-blank-slot)
  53.   (add-raised-slot '())         ; slot 13
  54.   (add-carriage-return-slot)
  55.  
  56.   (add-raised-slot '())         ; slot 14
  57.   (add-normal-slot '())         ; slot 15 (foundation)
  58.   (add-normal-slot '())         ; slot 16 (foundation)
  59.   (add-normal-slot '())         ; slot 17 (foundation)
  60.   (add-normal-slot '())         ; slot 18 (foundation)
  61.   (add-raised-slot '())         ; slot 19
  62.   (add-carriage-return-slot)
  63.  
  64.   (add-raised-slot '())         ; slot 20
  65.   (add-normal-slot '())         ; slot 21
  66.   (add-normal-slot '())         ; slot 22
  67.   (add-normal-slot '())         ; slot 23
  68.   (add-normal-slot '())         ; slot 24
  69.   (add-raised-slot '())         ; slot 25
  70.  
  71.   (set! open-royal 5)
  72.   (set! open-foundation 15)
  73.  
  74.   (deal-cards-face-up stock reserves)
  75.   (give-status)
  76.  
  77.   (list 6 5)
  78. )
  79.  
  80. (define (add-raised-slot list)
  81.   (set! VERTPOS (- VERTPOS 0.5))
  82.   (add-normal-slot list)
  83.   (set! VERTPOS (+ VERTPOS 0.5))
  84. )
  85.  
  86. (define (give-status)
  87.   (set-statusbar-message (format (_"Stock remaining: ~a")
  88.                                  (number->string (length (get-cards stock)))
  89.                          )
  90.   )
  91. )
  92.  
  93.  
  94. (define (button-pressed slot-id card-list)
  95.   (member slot-id (append (list waste) reserves))
  96. )
  97.  
  98. (define (droppable? start-slot card-list end-slot)
  99.   (and (not (null? (car card-list)))
  100.        (not (= start-slot end-slot))
  101.        (not (= end-slot stock))
  102.        (or (pair? (car card-list) (get-top-card end-slot) king queen)
  103.            (pair? (car card-list) (get-top-card end-slot) ace jack)
  104.            (and (not (empty-slot? end-slot))
  105.                 (member end-slot foundations)
  106.                 (= (get-suit (car card-list)) 
  107.                    (get-suit (get-top-card end-slot)))
  108.                 (= (+ (get-value (car card-list)) 1) 
  109.                    (get-value (get-top-card end-slot))
  110.                 )
  111.            )
  112.        )
  113.   )
  114. )
  115.  
  116. (define (pair? card1 card2 rank1 rank2)
  117.   (and (not (null? card1))
  118.        (not (null? card2))
  119.        (= (get-suit card1) (get-suit card2))
  120.        (or (and (= rank1 (get-value card1)) (= rank2 (get-value card2)))
  121.            (and (= rank1 (get-value card2)) (= rank2 (get-value card1)))
  122.        )
  123.   )
  124. )
  125.  
  126. (define (button-released start-slot card-list end-slot)
  127.   (if (droppable? start-slot card-list end-slot)
  128.       (if (member end-slot foundations)
  129.           (begin
  130.             (move-n-cards! start-slot end-slot card-list)
  131.             (add-to-score! 1)
  132.             (fill-gaps reserves)
  133.           )
  134.           (if (or (= ace (get-value (car card-list))) 
  135.                   (= jack (get-value (car card-list)))
  136.               )
  137.               (move-pair start-slot card-list end-slot open-foundation)
  138.               (move-pair start-slot card-list end-slot open-royal)
  139.           )
  140.       )
  141.       #f
  142.   )
  143. )
  144.  
  145. (define (move-pair start-slot card-list end-slot destination)
  146.   (remove-card end-slot)
  147.   (if (member destination foundations)
  148.       (begin
  149.         (add-card! destination (make-visible 
  150.                                  (make-card jack (get-suit (car card-list))))
  151.                                )
  152.         (set! open-foundation (+ open-foundation 1))
  153.       )
  154.       (begin
  155.         (add-card! destination (make-visible
  156.                                  (make-card king (get-suit (car card-list))))
  157.                                )
  158.         (add-card! destination (make-visible
  159.                                  (make-card queen (get-suit (car card-list))))
  160.                                )
  161.         (set! open-royal (+ open-royal 1))
  162.       )
  163.   )
  164.   (add-to-score! 2)
  165.   (fill-gaps reserves)
  166. )  
  167.  
  168. (define (fill-gaps slot-list)
  169.   (if (or (and (empty-slot? waste) (empty-slot? stock)) (null? slot-list))
  170.     #t
  171.     (begin
  172.       (if (empty-slot? (car slot-list))
  173.           (if (empty-slot? waste)
  174.               (deal-cards-face-up stock (list (car slot-list)))
  175.               (deal-cards-face-up waste (list (car slot-list)))
  176.           )          
  177.       )
  178.       (fill-gaps (cdr slot-list))
  179.     )
  180.   )
  181. )   
  182.  
  183.  
  184. (define (button-clicked slot-id)
  185.   (if (= slot-id stock)
  186.       (flip-stock stock waste 0)
  187.       #f
  188.   )
  189. )
  190.  
  191. (define (button-double-clicked slot-id)
  192.   (if (member slot-id (append (list waste) reserves))
  193.     (let ((move (check-moves-helper slot-id 
  194.                    (append (list waste) reserves foundations)
  195.                 )
  196.          ))
  197.       (if move
  198.         (begin
  199.           (button-released slot-id (list (remove-card slot-id)) (cadr move))
  200.           (fill-gaps reserves)
  201.         )
  202.         #f
  203.       )
  204.     )
  205.     #f
  206.   )
  207. )
  208.  
  209. (define (game-continuable)
  210.   (give-status)
  211.   (and (get-hint)
  212.        (not (game-won))
  213.   )
  214. )
  215.  
  216. (define (game-won)
  217.   (= 52 (get-score))
  218. )
  219.  
  220. (define (get-hint)
  221.   (define move (or (check-moves (append (list waste) reserves) foundations)
  222.                    (check-moves (append (list waste) reserves) reserves))
  223.   )
  224.   (if move
  225.       (list 1 (get-name(get-top-card(car move)))
  226.               (get-name(get-top-card(cadr move)))
  227.       )
  228.       (and (not (empty-slot? stock)) (list 0 (_"Deal a new card")))
  229.   )
  230. )
  231.  
  232. (define (check-moves from-list to-list)
  233.   (if (not (null? from-list))
  234.     (begin
  235.       (or (check-moves-helper (car from-list) to-list)
  236.           (check-moves (cdr from-list) (delete (car from-list) to-list))
  237.       )
  238.     )
  239.     #f
  240.   )
  241. )
  242.  
  243. (define (check-moves-helper item to-list)
  244.   (if (not (null? to-list))
  245.     (begin
  246.       (if (droppable? item (list (get-top-card item)) (car to-list))
  247.         (list item (car to-list))
  248.         (check-moves-helper item (cdr to-list))
  249.       )
  250.     )
  251.     #f
  252.   )
  253. )
  254.  
  255. (define (get-options) 
  256.   #f)
  257.  
  258. (define (apply-options options) 
  259.   #f)
  260.  
  261. (define (timeout) 
  262.   #f)
  263.  
  264. (set-features droppable-feature)
  265.  
  266. (set-lambda new-game button-pressed button-released button-clicked
  267. button-double-clicked game-continuable game-won get-hint get-options
  268. apply-options timeout droppable?)
  269.